package Twice.day10;

import java.util.Calendar;
import java.util.Date;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/8/13
 * @Version: 1.0
 */
public class CalendarDemo {
    public static void main(String[] args) {
        //通过简单工厂模式来构建日历对象
        //Calendar - 抽象类 - 永远是不能够被实例化的

        //面向父类编程 - 父类 对象 =new 子类()
        Calendar cal = Calendar.getInstance();

        //Calendar c = new GregorianCalendar();

        //System.out.println(new GregorianCalendar().isLeapYear(2012));

        System.out.println(cal);

        //将日历转换成日期
        Date date = cal.getTime();
        System.out.println(date);

        //日期转换成日历
        Date at = new Date(System.currentTimeMillis());
        cal.setTime(at);
        System.out.println(cal);

        //重新设置cal
        //根据指定的年月日来构建

        //统一进行赋值
        cal.set(2020,4,1);
        System.out.println(cal.getTime());

        //返回指定日历字段的值
        int year = cal.get(Calendar.YEAR);
        System.out.println("year = " + year);

        System.out.println(cal.get(Calendar.MONTH)+1);

        System.out.println(cal.get(Calendar.DAY_OF_WEEK));

        System.out.println(cal.get(Calendar.DAY_OF_MONTH));

        System.out.println(cal.get(Calendar.HOUR));

        System.out.println(cal.get(Calendar.HOUR_OF_DAY));
        System.out.println("============");

        Calendar dar = Calendar.getInstance();
        dar.set(Calendar.YEAR,2012);
        dar.set(Calendar.MONTH,7);
        System.out.println(dar.getTime());
    }
}
